﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DataShow
{
    public partial class ZDEdit : System.Web.UI.Page
    {
        protected string IndexUrl = "/Index.aspx";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToBoolean(Session["isadmin"]) == false)
            {
                IndexUrl = "ForecasterIndex.aspx";
            }
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            string sql = "select top 1 * from msg";
            txt_fwzd.Text = new codeDAL.SqlHelper().ExecuteScalar(sql);
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {

            string newcontent = txt_fwzd.Text;
            string checksql = "select * from msg", sql = "";
            if (new codeDAL.SqlHelper().ExecuteQuery(checksql, System.Data.CommandType.Text).Rows.Count > 0)
            {
                sql = string.Format("update msg set msg='{0}'", newcontent);
            }
            else
            {
                sql = string.Format("insert into msg values('{0}')", newcontent);
            }
            new codeDAL.SqlHelper().ExecuteNonQuery(sql, null);
            Common.RegisterScriptAtPageLast(Page, "alert('更新成功')");
        }
        

    }
}